package com.itheima.web.manager;
import com.itheima.domain.mongo.Movement;
import com.itheima.service.mongo.MovementService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.bson.types.ObjectId;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;

@Component
public class MovementManager {
    @DubboReference
    private MovementService movementService;

    /**
     * 动态复审-通过
     * @param movementIdList 动态id集合
     * @return
     */
    public ResponseEntity pass(String[] movementIdList) {

        for (String publishId : movementIdList) {
            //根据id查询动态
            Movement movement = movementService.findById(new ObjectId(publishId));

            //设置审核状态为1
            movement.setState(1);

            //更新辉数据库
            movementService.update(movement);

        }

        return ResponseEntity.ok("操作成功");
    }

    /**
     * 动态复审-驳回
     */
    public ResponseEntity reject(String[] movementIdList) {
        for (String publishId : movementIdList) {
            //根据id查询动态
            Movement movement = movementService.findById(new ObjectId(publishId));

            //设置审核状态为1
            movement.setState(2);

            //更新辉数据库
            movementService.update(movement);

        }

        return ResponseEntity.ok("操作成功");
    }
}
